package com.design.mall;

import com.design.mall.impl.CashDiscount;
import com.design.mall.impl.CashNormal;
import com.design.mall.impl.CashRebate;

import java.util.Objects;
import java.util.Scanner;

/**
 * @author by liuxin
 * @version 0.1
 */
public class Client {

    public static void main(String[] args) {
        CashContext cashContext = null;
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入打折方式（1/2/3）：");
        int in = scanner.nextInt();
        String type = "";

        switch (in) {
            case 1 -> {
                cashContext = new CashContext(new CashNormal());
                type += "正常收费";
            }
            case 2 -> {
                cashContext = new CashContext(new CashRebate(300, 100));
                type += "满300返100";
            }
            case 3 -> {
                cashContext = new CashContext(new CashDiscount(0.8));
                type += "打8折";
            }
            default -> System.out.println("请输入1/2/3");
        }

        double totalPrices;

        System.out.print("请输入单价：");
        double price = scanner.nextDouble();
        System.out.print("请输入数量：");
        double num = scanner.nextDouble();
        totalPrices = Objects.requireNonNull(cashContext).pay(price * num);

        System.out.println("单价：" + price + "，数量：" + num + "，类型：" + type + "，合计：" + totalPrices);

        scanner.close();
    }
}
